# 示例
import time
import random

from playwright.sync_api import sync_playwright
from playwright.sync_api import Page

def run(playwright):
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context(
        # 在这里添加你的伪装设置
        user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
    )
    context.add_init_script(path="./libs/stealth.min.js")
    page = context.new_page()

    page.goto("https://jd.com")

    # 暂停脚本，并启动 Playwright Inspector，此时可以手动操作
    page.pause()
    
    context.close()
    browser.close()

def get_locator(page: Page, selector: str):
    time.sleep(random.uniform(0.5, 1.5))  # 模拟人类操作的随机延迟
    return page.locator(selector)

with sync_playwright() as playwright:
    run(playwright)